<?php
namespace apps\manage\controllers;

use Yii;
use common\forms\login\LoginForm;


/**
 * 通行证控制器
 */
class PassportController extends \heihei\rest\Controller
{
    /**
     * 账号登录
     *
     * @return string
     */
    public function actionLogin()
    {
        $reqeust = Yii::$app->getRequest();
        $loginForm = new LoginForm();
        $loginForm->load(Yii::$app->request->post(), '');
        $result =  $loginForm->login();
        if (!$result) {
            $error = $loginForm->getFirstErrors();
            return $this->fail($error ? reset($error) : '未知错误');
        }

        $session = Yii::$app->getSession();
        $result['session_id'] =  $session->getId();
        $result['session_name'] =  $session->getName();
        
        return $result;      
    }

    /**
     * 三方授权登录 
     * @TODO
     *
     * @return string
     */
    public function actionAuthLogin()
    {
        return "三方授权登录";
    }

    /**
     * 扫描登录
     * @TODO
     *
     * @return string
     */
    public function actionScanLogin()
    {
        return "扫描登录";
    }

    /**
     * 账号退出 
     *
     * @return string
     */
    public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }
}
